<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" href="lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>选择优惠方案</title>
</head>
<style>
    .table>tbody>tr>td{
        text-align:center;
    }
</style>
<body>
<div style="padding:2vw">
    <table class="table table-border table-bordered table-bg table-hover table-sort" width="100%">
        <thead>
        <tr class="text-c">
            <th width="70">ID</th>
            <th width="70">优惠方式</th>
            <th width="80">操作</th>
        </tr>
        </thead>
    </table>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/common.js"></script>
<script type="text/javascript">
    var sEcho = 0
    function loadData(sSource,aoData, fnCallback){
        var pageNo = 0;
        var pageSize = 10;
        var start = 0;
        var length = 10;
        for(var i = 0;i<aoData.length;i++){
            var item = aoData[i];
            if(item.name == "start"){
                start = item.value;
            }else if(item.name == "length"){
                length = item.value;
            }
        }
        pageSize = length;
        pageNo = parseInt(start / pageSize);
        $.ajax({
            url : "/sys/preferential/page",//这个就是请求地址对应sAjaxSource
            data : {
                pageNo:pageNo,
                pageSize:pageSize
            },//这个是把datatable的一些基本数据传给后台,比如起始位置,每页显示的行数
            type : 'GET',
            dataType : 'json',
            async : false,
            success : function(result) {
                var res = {}
                res.sEcho = sEcho + 1
                sEcho += 1
                res.iTotalRecords = result.totalCount
                // res.iTotalDisplayRecords = (result.hasPre == true?result.prePage * result.pageParam.pageSize:0) + result.result.length
                res.iTotalDisplayRecords = result.totalCount
                res.aaData = result.result
                fnCallback(res);//把返回的数据传给这个方法就可以了,datatable会自动绑定数据的
            },
            error : function(msg) {
            }
        });
    }

    /*datatables配置*/
    $(document).ready(function () {
        $('.table').DataTable({
            "serverSide": true,//开启服务器模式:启用服务器分页
            paging : true,//是否分页
            pagingType : "full_numbers",//除首页、上一页、下一页、末页四个按钮还有页数按钮
            "processing": true,//加载显示提示
            "fnServerData": loadData, // 获取数据的处理函数
            "aoColumns": [
                { "data": "id"},
                { "data": "content"},
                {
                    "data": null,
                    render: function (data, type, row, meta) {
                        return "<input onclick='choosePreferential()' class='btn btn-danger-outline size-S radius' type='button' value='选择该优惠方案'>";
                    }
                }
            ],
            "aaSorting": [[ 0, "asc" ]],//默认第几个排序
            "bStateSave": false,//状态保存
            "aoColumnDefs": [
                {"orderable":false,"aTargets":[1,2]}// 制定列不参与排序
            ],
            language: {
                url: '/lib/datatables/Chinese.json'
            },
            colReorder: true
        });
    });

    function choosePreferential(){
        var table = $('.table').DataTable();
        $('.table tbody').on( 'click', 'tr', function () {
            var id = table.row( this ).data().id;
            var content = table.row( this ).data().content;
            parent.setPreferential(id,content);
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });
    }
</script>
</body>
</html>
